package com.xx.doublexchat.common.websocket.service.adapter;

import com.xx.doublexchat.common.chat.domain.vo.response.ChatMessageResponse;
import com.xx.doublexchat.common.common.domain.enums.YesOrNoEnum;
import com.xx.doublexchat.common.user.domain.entity.User;
import com.xx.doublexchat.common.websocket.domain.enums.WSRespTypeEnum;
import com.xx.doublexchat.common.websocket.domain.vo.resp.*;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

public class WebSocketAdapter {
    /**
     * 封装返回给前端信息
     * @param wxMpQrCodeTicket 微信二维码类
     * @return
     */
    public static WSBaseResponse<?> buildResponse(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WSBaseResponse<WSLoginUrl> response = new WSBaseResponse<>();
        response.setType(WSRespTypeEnum.LOGIN_URL.getType());
        response.setData(new WSLoginUrl(wxMpQrCodeTicket.getUrl()));
        return response;
    }

    /**
     * 封装用户成功消息
     * @param user user
     * @param token token
     * @param power 是否有权限标识
     * @return
     */
    public static WSBaseResponse<?> buildResponse(User user, String token, boolean power) {
        WSBaseResponse<WSLoginSuccess> response = new WSBaseResponse<>();
        response.setType(WSRespTypeEnum.LOGIN_SUCCESS.getType());
        WSLoginSuccess build = WSLoginSuccess.builder()
                .avatar(user.getAvatar())
                .name(user.getName())
                .token(token)
                .uid(user.getId())
                .power(power ? YesOrNoEnum.YES.getStatus() : YesOrNoEnum.NO.getStatus())
                .build();
        response.setData(build);
        System.out.println(WSRespTypeEnum.LOGIN_SUCCESS.getType()+WSRespTypeEnum.LOGIN_SUCCESS.getDesc());
        return response;
    }

    /**
     * 扫码成功等待授权
     * @return
     */
    public static WSBaseResponse<?> buildResponse() {
        WSBaseResponse<WSLoginUrl> response = new WSBaseResponse<>();
        response.setType(WSRespTypeEnum.LOGIN_SCAN_SUCCESS.getType());
        return response;
    }

    /**
     * 发送消息等待认证
     * @return
     */
    public static WSBaseResponse<?> buildInvalidTokenResponse() {
        WSBaseResponse<WSLoginUrl> response = new WSBaseResponse<>();
        response.setType(WSRespTypeEnum.INVALIDATE_TOKEN.getType());
        return response;
    }

    /**
     * 组装拉黑信息
     * @param user
     * @return
     */
    public static WSBaseResponse<?> buildBlack(User user) {
        WSBaseResponse<WSBlack> response = new WSBaseResponse<>();
        response.setType(WSRespTypeEnum.BLACK.getType());
        WSBlack build = WSBlack.builder()
                .uid(user.getId())
                .build();
        response.setData(build);
        System.out.println(WSRespTypeEnum.BLACK.getType() + WSRespTypeEnum.BLACK.getDesc());
        return response;
    }

    /**
     * 封装发送信息
     * @param msgResp
     * @return
     */
    public static WSBaseResponse<ChatMessageResponse> buildMsgSend(ChatMessageResponse msgResp) {
        WSBaseResponse<ChatMessageResponse> wsBaseResp = new WSBaseResponse<>();
        wsBaseResp.setType(WSRespTypeEnum.MESSAGE.getType());
        wsBaseResp.setData(msgResp);
        return wsBaseResp;
    }

    /**
     * 封装申请好友信息
     * @param wsFriendApply
     * @return
     */
    public static WSBaseResponse<?> buildApplySend(WSFriendApply wsFriendApply) {
        WSBaseResponse<WSFriendApply> wsBaseResp = new WSBaseResponse<>();
        wsBaseResp.setType(WSRespTypeEnum.APPLY.getType());
        wsBaseResp.setData(wsFriendApply);
        return wsBaseResp;
    }
}
